//
//  XWSongListViewController.m
//  CGWSWW
//
//  Created by lanou3g on 16/8/16.
//  Copyright © 2016年 CXG. All rights reserved.
//

#import "XWSongListViewController.h"
#import "XWSongTableView.h"
#import "XWHeadView.h"
#import "XWSongListModel.h"
#import "XWSongDetailModel.h"
#import "HeadHelp.h"
#import "XWUrl.h"
#import "XWNetWorkTool.h"
#import "XWCreatTool.h"
#import <MJExtension.h>
#import <UIImageView+WebCache.h>
@interface XWSongListViewController ()

@property (nonatomic ,weak) UIImageView *backGroundImageView;
@property (nonatomic ,weak) UIScrollView *scrollView;
@property (nonatomic ,strong) XWSongTableView *tableView;
@property (nonatomic ,strong) XWHeadView *headView;

@property (nonatomic ,strong) NSMutableArray *songListArrayM;
@property (nonatomic ,strong) NSMutableArray *songIdsArrayM;


@end

@implementation XWSongListViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBar.backgroundColor = XWRandomColor;
    [self setUpBackGroundView];
    [self setUpScrollView];
    self.songListArrayM = [NSMutableArray array];
    self.songIdsArrayM = [NSMutableArray array];
    [self loadSongList];
}
- (void)setUpBackGroundView
{
    self.backGroundImageView = [XWCreatTool imageViewWithView:self.view];
    self.backGroundImageView.frame = CGRectMake(-KScreen_Width,-KScreen_Height, 3 * KScreen_Width, 3 * KScreen_Height);
    [self.backGroundImageView sd_setImageWithURL:[NSURL URLWithString:self.pic]];

    UIToolbar *blurView = [[UIToolbar alloc] init];
    blurView.barStyle = UIBarStyleDefault;
    blurView.frame = self.backGroundImageView.frame;
    [self.backGroundImageView addSubview:blurView];
    
}
- (void)setUpScrollView
{
    self.scrollView = [XWCreatTool scrollViewWithView:self.view];
    self.scrollView.frame = self.view.frame;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.contentSize = CGSizeMake(0, KScreen_Height + KScreen_Width * 0.5 +60);
    
    self.headView = [[XWHeadView alloc] initWithFullHead:arc4random() % 2];
    self.headView.frame = CGRectMake(0, 40, KScreen_Width, KScreen_Width * 0.5 + 60);
    [self.scrollView addSubview:self.headView];
    
    self.tableView = [[XWSongTableView alloc] init];
    self.tableView.frame = CGRectMake(0, KScreen_Width * 0.5 + 100, KScreen_Width, KScreen_Height);
    [self.scrollView addSubview:self.tableView];
}

#pragma mark - loadData
- (void)loadSongList
{
    [XWNetWorkTool netWorkToolGetWithUrl:XWUrl parameters:XWParams(@"method":@"baidu.ting.diy.gedanInfo",@"listid":self.listid) response:^(id response) {
        XWSongListModel *songList = [XWSongListModel mj_objectWithKeyValues:response];
        NSInteger i = 0;
        for (NSDictionary *dict in songList.content) {
            XWSongDetailModel *songDetail = [XWSongDetailModel mj_objectWithKeyValues:dict];
            songDetail.num = ++i;
            [self.songListArrayM addObject:songDetail];
            [self.songIdsArrayM addObject:songDetail.song_id];
        }
        [self.headView setMenuList:songList];
        [self.tableView setSongList:self.songListArrayM songIds:self.songIdsArrayM];
    }];
}

@end
